package com.ithiema.edu.info.manager.service;

import com.ithiema.edu.info.manager.dao.StudentDao;

import com.ithiema.edu.info.manager.domain.Student;
import com.ithiema.edu.info.manager.utils.Utils;

public class StudentService {
    //创建工具类对象
    Utils utils = new Utils();
    //创建StudentDao对象
    StudentDao stuDao = new StudentDao();
    //获取学生数组
    Student[] stus = stuDao.findAllStudent();

    //添加学员方法
    public boolean addStudent(Student student) {
        //调用StudentDao中addStudent方法，判断是否添加成功
        boolean flag = stuDao.addStudent(student);
        return flag;
    }

    //判断学生数组中是否存在相同学号
    public boolean seekIndex(String id) {
        return utils.seekIndex(id,stus);
    }

    //展示学员信息
    public void ShowStudent() {
        System.out.println("学号\t\t姓名\t\t性别\t\t生日");
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null) {
                continue;
            }
            Student stu = stus[i];
            System.out.println(stu.getId() + "\t" + stu.getName() + "\t\t" + stu.getSex()
                    + "\t\t" + stu.getBirthday());
        }
    }

    //根据id删除学员信息
    public boolean deleteStudent(String id) {
        return stuDao.deleteStudent(id);
    }

    //根据id修改学员信息
    public void reviseStudent(String id, Student stu) {
        stuDao.reviseStudent(id, stu);
    }
}
